/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ge.ktools;

import ge.info.domain.Organization;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author koka
 */
public class Utils
{

    public static List<Organization> sortOrganizations(List<Organization> list, Organization org)
    {

        if (list == null)
        {
            return null;
        }







        List<Organization> listSorted = new ArrayList<Organization>();

        //Kakha start
        for (Organization organization : list)
        {
            if (org.getName() != null && organization.getEprior()<0)
            {
                listSorted.add(organization);
            }
        }

        //Kakha end
        for (Organization organization : list)
        {
            if (org.getName() != null && organization.getName().indexOf(org.getName()) > -1)
            {
                listSorted.add(organization);
            }
        }

        for (Organization organization : list)
        {
            if (!listSorted.contains(organization))
            {
                if (org.getName() != null && StringUtils.containsAllStrings(organization.getName(), StringUtils.splitString(org.getName())))
                {
                    listSorted.add(organization);
                }
            }
        }
        for (Organization organization : list)
        {
            if (!listSorted.contains(organization))
            {
                listSorted.add(organization);
            }
        }
        return listSorted;
    }
}
